home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / www / src / midaswww-1.0 / SGMLText.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-16  |  27.8 KB  |  750 lines

  1. /*==================================================================*/
  2. /*                                                                  */
  3. /* SGMLTextObject                                                   */
  4. /*                                                                  */
  5. /* T.Johnson - (TonyJ@Slacvx.Slac.Stanford.Edu)           June.92   */
  6. /*                                                                  */
  7. /* Defines a text segment for the SGMLHyper widget                  */
  8. /*                                                                  */
  9. /*==================================================================*/
  10.  
  11. #include <X11/IntrinsicP.h>
  12. #include <X11/StringDefs.h>
  13. #include <X11/CoreP.h>
  14. #include "SGMLTextP.h"
  15. #include "SGMLHyperP.h"
  16.  
  17. /* 
  18.   Private functions 
  19. */
  20.  
  21. #define max(a,b) (a>b?a:b)
  22. void _SGMLBreak(); 
  23.  
  24. /*
  25.   Widget class methods
  26. */
  27.  
  28. static void    ClassPartInitialize();
  29. static void    Initialize();
  30. static void    ClassInitialize();
  31. static void    Destroy();
  32. static Boolean SetValues();
  33. static void    ComputeSize();
  34. static Boolean AdjustSize();
  35. static void    AdjustPosition();
  36. static void    Redisplay();
  37. static void    Activate();
  38. static void    Hilite();
  39. static Widget  Contains();
  40. static void    CallCreateCallback();
  41. static void    CallMapCallback();
  42. static void    MakeVisible();
  43.  
  44. #define Offset(field) XtOffsetOf(SGMLTextRec,sgml_text.field)
  45.  
  46. static XtResource resources[] = {
  47.  
  48.     {SGMLNtext, SGMLCText, XtRString, sizeof(String),
  49.     Offset(text), XtRString, ""},
  50.  
  51.     {SGMLNparam, SGMLCParam, XtRString, sizeof(String),
  52.     Offset(param), XtRString, ""},
  53.  
  54.     {SGMLNlength, SGMLCLength, XtRInt, sizeof(int),
  55.     Offset(length), XtRImmediate, 0},
  56.  
  57.     {SGMLNparamLength, SGMLCParamLength, XtRInt, sizeof(int),
  58.     Offset(param_length), XtRImmediate, 0},
  59.  
  60.     {SGMLNfont, SGMLCFont, XtRFontStruct, sizeof (XFontStruct *),
  61.     Offset(normal_rendition.font), XtRString, SGMLINHERIT_FONT},
  62.  
  63.     {SGMLNcolor, SGMLCColor, XtRPixel, sizeof (Pixel),
  64.     Offset(normal_rendition.color),XtRString, SGMLINHERIT_COLOR},
  65.  
  66.     {SGMLNoutline,SGMLCOutline,XtRBoolean,sizeof(Boolean),
  67.     Offset (normal_rendition.outline),XtRImmediate,(XtPointer)SGMLINHERIT_OUTLINE},
  68.  
  69.     {SGMLNunderline,SGMLCUnderline,XtRInt,sizeof(int),
  70.     Offset (normal_rendition.underline),XtRImmediate,(XtPointer)SGMLINHERIT_UNDERLINE},
  71.  
  72.     {SGMLNunderlineHeight, SGMLCUnderlineHeight, XtRDimension, sizeof(Dimension),
  73.     Offset (normal_rendition.underline_height),XtRImmediate,(XtPointer)SGMLINHERIT_UNDERLINEHEIGHT},
  74.  
  75.     {SGMLNsensitiveFont, SGMLCFont, XtRFontStruct, sizeof (XFontStruct *),
  76.     Offset(sensitive_rendition.font), XtRString, SGMLINHERIT_FONT},
  77.  
  78.     {SGMLNsensitiveColor, SGMLCColor, XtRPixel, sizeof (Pixel),
  79.     Offset(sensitive_rendition.color),XtRString, SGMLINHERIT_COLOR},
  80.  
  81.     {SGMLNsensitiveOutline,SGMLCOutline,XtRBoolean,sizeof(Boolean),
  82.     Offset (sensitive_rendition.outline),XtRImmediate,(XtPointer)SGMLINHERIT_OUTLINE},
  83.  
  84.     {SGMLNsensitiveUnderline,SGMLCUnderline,XtRInt,sizeof(int),
  85.     Offset (sensitive_rendition.underline),XtRImmediate,(XtPointer)SGMLINHERIT_UNDERLINE},
  86.  
  87.     {SGMLNsensitiveUnderlineHeight, SGMLCUnderlineHeight, XtRDimension, sizeof(Dimension),
  88.     Offset (sensitive_rendition.underline_height),XtRImmediate,(XtPointer)SGMLINHERIT_UNDERLINEHEIGHT},
  89.  
  90.     {SGMLNbreakBefore,SGMLCBreak,SGMLRBreak,sizeof(int),
  91.     Offset (break_before),XtRImmediate,(XtPointer)FALSE},
  92.  
  93.     {SGMLNbreakAfter,SGMLCBreak,SGMLRBreak,sizeof(int),
  94.     Offset (break_after),XtRImmediate,(XtPointer)FALSE},
  95.  
  96.     {SGMLNsensitive,SGMLCSensitive,XtRBoolean,sizeof(Boolean),
  97.     Offset (sensitive),XtRImmediate,(XtPointer)SGMLINHERIT_SENSITIVITY},
  98.  
  99.     {SGMLNrightMargin,SGMLCMargin,XtRInt,sizeof(int),
  100.     Offset (right_margin),XtRImmediate,(XtPointer)SGMLINHERIT_MARGIN},
  101.  
  102.     {SGMLNleftMargin,SGMLCMargin,XtRInt,sizeof(int),
  103.     Offset (left_margin),XtRImmediate,(XtPointer)SGMLINHERIT_MARGIN},
  104.  
  105.     {SGMLNrightIndent,SGMLCMargin,XtRInt,sizeof(int),
  106.     Offset (right_indent),XtRImmediate,(XtPointer)0},
  107.  
  108.     {SGMLNleftIndent,SGMLCMargin,XtRInt,sizeof(int),
  109.     Offset (left_indent),XtRImmediate,(XtPointer)0},
  110.  
  111.     {SGMLNparagraphIndent,SGMLCMargin,XtRInt,sizeof(int),
  112.     Offset (paragraph_indent),XtRImmediate,(XtPointer)SGMLINHERIT_PARAGRAPHINDENT},
  113.  
  114.     {SGMLNalignment,SGMLCAlignment,XtRInt,sizeof(int),
  115.     Offset (alignment),XtRImmediate,(XtPointer)SGMLINHERIT_ALIGNMENT},
  116.  
  117.     {SGMLNspacing,SGMLCSpacing,XtRDimension,sizeof(Dimension),
  118.     Offset (spacing),XtRImmediate,(XtPointer)0},
  119.  
  120.     {SGMLNspaceBefore,SGMLCSpacing,XtRDimension,sizeof(Dimension),
  121.     Offset (space_before),XtRImmediate,0},
  122.  
  123.     {SGMLNspaceAfter,SGMLCSpacing,XtRDimension,sizeof(Dimension),
  124.     Offset (space_after),XtRImmediate,0},
  125.  
  126.     {SGMLNdepth,SGMLCDepth,XtRDimension,sizeof(Dimension),
  127.     Offset (depth),XtRImmediate,(XtPointer)0},
  128.  
  129.     {SGMLNascent,SGMLCAscent,XtRDimension,sizeof(Dimension),
  130.     Offset (ascent),XtRImmediate,(XtPointer)0},
  131.  
  132.     {SGMLNuserdata,SGMLCUserdata,XtRPointer,sizeof(XtPointer),
  133.     Offset (userdata),XtRImmediate,(XtPointer)0},
  134.  
  135.     {SGMLNactivateCallback,SGMLCCallback,XtRCallback,sizeof(caddr_t),
  136.     Offset (activate),XtRCallback,NULL},
  137.  
  138.     {SGMLNmapCallback,SGMLCCallback,XtRCallback,sizeof(caddr_t),
  139.     Offset (map),XtRCallback,NULL},
  140.  
  141.      {SGMLNcreateCallback, SGMLCCallback, XtRCallback, sizeof(caddr_t),
  142.     Offset (create),XtRCallback,NULL} 
  143.     
  144. };
  145. #undef Offset
  146.  
  147. /*---------------------------------------------------------------*/
  148. /* Static initialisation of the class record                     */
  149. /*---------------------------------------------------------------*/
  150.  
  151. SGMLTextClassRec  sGMLTextClassRec = {
  152.     {
  153.     (WidgetClass) &objectClassRec,       /* superclass            */
  154.     "SGMLText",                          /* class_name            */
  155.     sizeof(SGMLTextRec),                 /* widget_size           */
  156.     ClassInitialize,                     /* class_initialize      */
  157.     ClassPartInitialize,                 /* class_part_initialize */
  158.     FALSE,                               /* class_inited          */
  159.     Initialize,                          /* initialize            */
  160.     NULL,                                /* initialize_hook       */
  161.     NULL,                                /* obj1                  */
  162.     NULL,                                /* obj2                  */
  163.     0,                                   /* obj3                  */
  164.     resources,                           /* resources             */
  165.     XtNumber(resources),                 /* num_resources         */
  166.     NULLQUARK,                           /* xrm_class             */
  167.     0,                                   /* obj4                  */
  168.     0,                                   /* obj5                  */
  169.     0,                                   /* obj6                  */
  170.     0,                                   /* obj7                  */
  171.     Destroy,                             /* destroy               */
  172.     NULL,                                /* obj8                  */
  173.     NULL,                                /* obj9                  */
  174.     SetValues,                           /* set_values            */
  175.     NULL,                                /* set_values_hook       */
  176.     NULL,                                /* obj10                 */
  177.     NULL,                                /* get_values_hook       */
  178.     NULL,                                /* obj11                 */
  179.     XtVersion,                           /* version               */
  180.     NULL,                                /* callback private      */
  181.     NULL,                                /* obj12                 */
  182.     NULL,                                /* obj13                 */
  183.     NULL,                                /* obj14                 */
  184.     NULL,                                /* extension             */
  185.     },
  186.     {
  187.     ComputeSize,                   /* compute_size          */
  188.     AdjustSize,                   /* adjust_size           */
  189.     AdjustPosition,                   /* adjust_position       */
  190.     Redisplay,                           /* expose                */
  191.     Activate,                            /* activate              */
  192.     Hilite,                              /* hilite                */
  193.     Contains,                            /* contains              */
  194.     CallCreateCallback,                  /* call_create_callback  */ 
  195.     CallMapCallback,                     /* call_map_callback     */ 
  196.     MakeVisible,                         /* make_visible          */
  197.     NULL,                                /* extension             */
  198.     }
  199. };
  200.  
  201. WidgetClass sGMLTextObjectClass = (WidgetClass) &sGMLTextClassRec;
  202.  
  203. static void CvtStringToBreak (args, num_args, fromVal, toVal)
  204.     XrmValuePtr args;
  205.     Cardinal    *num_args;
  206.     XrmValuePtr fromVal;
  207.     XrmValuePtr toVal;
  208. {
  209.     char *s;
  210.     static int flag;
  211.        
  212.     if (*num_args != 0)
  213.         XtWarningMsg("wrongParameters","cvtStringToBreak","XtToolkitError",
  214.                   "String to Break conversion needs no extra arguments",
  215.                   (String *) NULL, (Cardinal *)NULL);
  216.  
  217.     s = (char *) fromVal->addr;
  218.     flag = SGMLBREAK_NEVER;
  219.  
  220.     if      (!strcmp(s,"SGMLBREAK_NEVER" )) flag = SGMLBREAK_NEVER; 
  221.     else if (!strcmp(s,"SGMLBREAK_ALWAYS")) flag = SGMLBREAK_ALWAYS; 
  222.     else if (!strcmp(s,"SGMLBREAK_SOFT"))   flag = SGMLBREAK_SOFT; 
  223.     else XtStringConversionWarning((char *) fromVal->addr, SGMLRBreak);
  224.  
  225.     toVal->size = sizeof(flag);
  226.     toVal->addr = (XtPointer) &flag;
  227. }
  228.  
  229. /*--------------------------------------------------------------*/
  230. /* ClassInitialize: Register the converters                     */
  231. /*--------------------------------------------------------------*/
  232.  
  233. static void ClassInitialize()
  234. {
  235.    XtAddConverter (XtRString, SGMLRBreak, CvtStringToBreak,
  236.                (XtConvertArgList) NULL, (Cardinal) 0);
  237. }
  238. /*--------------------------------------------------------------*/
  239. /* SetFontInfo: (private function)                              */
  240. /*--------------------------------------------------------------*/
  241. static void SetFontInfo(new)
  242. SGMLTextObject new;
  243. {
  244.     /* if possible we will inherit graphic contexts from our parent */ 
  245.  
  246.     SGMLTextObject parent = (SGMLTextObject) XtParent((Widget) new);
  247.     SGMLRendition  *rendition, *parent_rendition;
  248.     int dir, ascent, descent;
  249.     XCharStruct charinfo;
  250.  
  251.     if (parent->sgml_text.sensitive) parent_rendition = &parent->sgml_text.sensitive_rendition;
  252.     else                             parent_rendition = &parent->sgml_text.normal_rendition;
  253.  
  254.     if (new->sgml_text.sensitive) rendition = &new->sgml_text.sensitive_rendition;
  255.     else                          rendition = &new->sgml_text.normal_rendition;
  256.  
  257.     if (parent_rendition->color       == rendition->color &&
  258.         parent_rendition->font        == rendition->font  &&
  259.         parent_rendition->underline_height  
  260.                                       == rendition->underline_height )
  261.       {    
  262.  
  263.         new->sgml_text.gc        = parent->sgml_text.gc;
  264.         new->sgml_text.invert_gc = parent->sgml_text.invert_gc;
  265.         new->sgml_text.own_gcs   = FALSE;
  266.       }
  267.     else
  268.       {
  269.         XGCValues values;
  270.         XtGCMask  valueMask;
  271.         Pixel background, color; 
  272.         Widget w;
  273.         Visual *Vis; 
  274.                
  275.         for (w=XtParent((Widget) new); !XtIsWidget(w); w= XtParent(w));
  276.         background = w->core.background_pixel; 
  277.         
  278.         valueMask = GCForeground | GCFont | GCLineWidth | GCLineStyle;
  279.   
  280.         if (DefaultDepthOfScreen(XtScreen(w))==1) color = 1 - background;
  281.         else color = rendition->color;
  282.  
  283.         values.foreground = color;
  284.         values.font       = rendition->font->fid;
  285.         values.line_width = rendition->underline_height;
  286.         values.line_style = LineSolid;
  287.  
  288.         new->sgml_text.gc = XtGetGC ((Widget) new, valueMask, &values);
  289.    
  290.         valueMask = GCForeground | GCFunction;
  291.         values.foreground = background ^ color;
  292.         values.function   = GXxor;
  293.         new->sgml_text.invert_gc = XtGetGC ((Widget) new, valueMask, &values);
  294.  
  295.         new->sgml_text.own_gcs   = TRUE;
  296.     
  297.       }
  298.     XTextExtents(rendition->font," ",1,&dir,&ascent,&descent,&charinfo);
  299.  
  300.     new->sgml_text.ascent  = ascent;
  301.     new->sgml_text.depth   = ascent + max(descent,2*max(rendition->underline_height,1)*
  302.                                                     rendition->underline);
  303.     new->sgml_text.spacing = charinfo.width;
  304. }
  305.  
  306. /*--------------------------------------------------------------*/
  307. /* FreeFontInfo: (private function)                             */
  308. /*--------------------------------------------------------------*/
  309. static void FreeFontInfo(new)
  310. SGMLTextObject new;
  311. {
  312.     if (new->sgml_text.own_gcs)
  313.       {
  314.         XtReleaseGC((Widget) new, new->sgml_text.gc);
  315.         XtReleaseGC((Widget) new, new->sgml_text.invert_gc);
  316.         new->sgml_text.own_gcs = FALSE;
  317.       }
  318. }
  319. /*--------------------------------------------------------------*/
  320. /* ClassPartInitialize:                                         */
  321. /*--------------------------------------------------------------*/
  322.  
  323. static void ClassPartInitialize (class)
  324. SGMLTextObjectClass class;
  325. {
  326.    SGMLTextObjectClass superclass = (SGMLTextObjectClass) class->object_class.superclass; 
  327.       
  328.    if (class->sgml_text_class.compute_size == SGMLInheritComputeSize)
  329.        class->sgml_text_class.compute_size = superclass->sgml_text_class.compute_size;
  330.  
  331.    if (class->sgml_text_class.adjust_size == SGMLInheritAdjustSize)
  332.        class->sgml_text_class.adjust_size = superclass->sgml_text_class.adjust_size;
  333.  
  334.    if (class->sgml_text_class.adjust_position == SGMLInheritAdjustPosition)
  335.        class->sgml_text_class.adjust_position = superclass->sgml_text_class.adjust_position;
  336.  
  337.   if (class->sgml_text_class.compute_size == SGMLInheritComputeSize)
  338.        class->sgml_text_class.compute_size = superclass->sgml_text_class.compute_size;
  339.  
  340.  
  341.    if (class->sgml_text_class.expose == SGMLInheritExpose)
  342.        class->sgml_text_class.expose = superclass->sgml_text_class.expose;
  343.  
  344.    if (class->sgml_text_class.activate == SGMLInheritActivate)
  345.        class->sgml_text_class.activate = superclass->sgml_text_class.activate;
  346.  
  347.    if (class->sgml_text_class.hilite == SGMLInheritHilite)
  348.        class->sgml_text_class.hilite = superclass->sgml_text_class.hilite;
  349.  
  350.    if (class->sgml_text_class.contains == SGMLInheritContains)
  351.        class->sgml_text_class.contains = superclass->sgml_text_class.contains;
  352.  
  353.    if (class->sgml_text_class.call_create_callback == SGMLInheritCallCreateCallback)
  354.        class->sgml_text_class.call_create_callback = superclass->sgml_text_class.call_create_callback;
  355.  
  356.    if (class->sgml_text_class.call_map_callback == SGMLInheritCallMapCallback)
  357.        class->sgml_text_class.call_map_callback = superclass->sgml_text_class.call_map_callback;
  358.  
  359.    if (class->sgml_text_class.make_visible == SGMLInheritMakeVisible)
  360.        class->sgml_text_class.make_visible = superclass->sgml_text_class.make_visible;
  361. }
  362. /*--------------------------------------------------------------*/
  363. /* Initialize:                                                  */
  364. /*--------------------------------------------------------------*/
  365.  
  366. static void Initialize (request, new)
  367. SGMLTextObject request, new;
  368. {
  369.    SGMLTextObject parent = (SGMLTextObject) XtParent((Widget) new);
  370.  
  371.    new->sgml_text.text   = new->sgml_text.text?XtNewString(new->sgml_text.text):NULL;
  372.    new->sgml_text.length = new->sgml_text.text?strlen(new->sgml_text.text):0;
  373.  
  374.    new->sgml_text.param        = new->sgml_text.param?XtNewString(new->sgml_text.param):NULL;
  375.    new->sgml_text.param_length = new->sgml_text.param?strlen(new->sgml_text.param):0;
  376.  
  377.    new->sgml_text.size_valid = FALSE;
  378.  
  379.     /*
  380.      * Many quantities can be inherited from our parent 
  381.      */
  382.  
  383.     if (SGMLIsText((Widget) parent))
  384.     {
  385.        new->sgml_text.left_indent  +=  parent->sgml_text.left_indent;
  386.        new->sgml_text.right_indent +=  parent->sgml_text.right_indent;
  387.  
  388.        if (new->sgml_text.left_margin == SGMLINHERIT_MARGIN)
  389.          new->sgml_text.left_margin = parent->sgml_text.left_margin;
  390.  
  391.        if (new->sgml_text.right_margin == SGMLINHERIT_MARGIN)
  392.          new->sgml_text.right_margin = parent->sgml_text.right_margin;
  393.  
  394.        if (new->sgml_text.paragraph_indent == SGMLINHERIT_PARAGRAPHINDENT)
  395.          new->sgml_text.paragraph_indent = parent->sgml_text.paragraph_indent;
  396.  
  397.        if (new->sgml_text.space_before == SGMLINHERIT_SPACE)
  398.          new->sgml_text.space_before = parent->sgml_text.space_before;
  399.  
  400.        if (new->sgml_text.space_after == SGMLINHERIT_SPACE)
  401.          new->sgml_text.space_after = parent->sgml_text.space_after;
  402.  
  403.        if (new->sgml_text.break_before == SGMLINHERIT_BREAK)
  404.          new->sgml_text.break_before = parent->sgml_text.break_before;
  405.  
  406.        if (new->sgml_text.break_after == SGMLINHERIT_BREAK)
  407.          new->sgml_text.break_after = parent->sgml_text.break_after;
  408.  
  409.        if (new->sgml_text.alignment == SGMLINHERIT_ALIGNMENT)
  410.          new->sgml_text.alignment = parent->sgml_text.alignment;
  411.  
  412.        if (new->sgml_text.sensitive == SGMLINHERIT_SENSITIVITY)
  413.          new->sgml_text.sensitive = parent->sgml_text.sensitive;
  414.  
  415.        if (new->sgml_text.normal_rendition.outline == SGMLINHERIT_OUTLINE)
  416.          new->sgml_text.normal_rendition.outline = parent->sgml_text.normal_rendition.outline;
  417.  
  418.        if (new->sgml_text.normal_rendition.underline == SGMLINHERIT_UNDERLINE)
  419.          new->sgml_text.normal_rendition.underline = parent->sgml_text.normal_rendition.underline;
  420.  
  421.        if (new->sgml_text.normal_rendition.underline_height == SGMLINHERIT_UNDERLINEHEIGHT)
  422.          new->sgml_text.normal_rendition.underline_height = parent->sgml_text.normal_rendition.underline_height;
  423.  
  424.        if (new->sgml_text.normal_rendition.font == SGMLINHERIT_FONT)
  425.          new->sgml_text.normal_rendition.font = parent->sgml_text.normal_rendition.font;
  426.  
  427.        if (new->sgml_text.normal_rendition.color == SGMLINHERIT_COLOR)
  428.          new->sgml_text.normal_rendition.color = parent->sgml_text.normal_rendition.color;
  429.  
  430.        if (new->sgml_text.sensitive_rendition.outline == SGMLINHERIT_OUTLINE)
  431.          new->sgml_text.sensitive_rendition.outline = parent->sgml_text.sensitive_rendition.outline;
  432.  
  433.        if (new->sgml_text.sensitive_rendition.underline == SGMLINHERIT_UNDERLINE)
  434.          new->sgml_text.sensitive_rendition.underline = parent->sgml_text.sensitive_rendition.underline;
  435.  
  436.        if (new->sgml_text.sensitive_rendition.underline_height == SGMLINHERIT_UNDERLINEHEIGHT)
  437.          new->sgml_text.sensitive_rendition.underline_height = parent->sgml_text.sensitive_rendition.underline_height;
  438.  
  439.        if (new->sgml_text.sensitive_rendition.font == SGMLINHERIT_FONT)
  440.          new->sgml_text.sensitive_rendition.font = parent->sgml_text.sensitive_rendition.font;
  441.  
  442.        if (new->sgml_text.sensitive_rendition.color == SGMLINHERIT_COLOR)
  443.          new->sgml_text.sensitive_rendition.color = parent->sgml_text.sensitive_rendition.color;
  444.     }
  445.     else
  446.     {
  447.        if (new->sgml_text.left_margin == SGMLINHERIT_MARGIN)
  448.          new->sgml_text.left_margin = ((SGMLHyperWidget) parent)->sgml_hyper.margin;
  449.  
  450.        if (new->sgml_text.right_margin == SGMLINHERIT_MARGIN)
  451.          new->sgml_text.right_margin = ((SGMLHyperWidget) parent)->sgml_hyper.margin;
  452.  
  453.        if (new->sgml_text.paragraph_indent == SGMLINHERIT_PARAGRAPHINDENT)
  454.          new->sgml_text.paragraph_indent = 0;
  455.  
  456.        if (new->sgml_text.space_before == SGMLINHERIT_SPACE)
  457.          new->sgml_text.space_before = 0;
  458.          
  459.        if (new->sgml_text.space_after == SGMLINHERIT_SPACE)
  460.          new->sgml_text.space_after = 0;
  461.  
  462.        if (new->sgml_text.break_before == SGMLINHERIT_BREAK)
  463.          new->sgml_text.break_before = FALSE;
  464.  
  465.        if (new->sgml_text.break_after == SGMLINHERIT_BREAK)
  466.          new->sgml_text.break_after = FALSE;
  467.  
  468.        if (new->sgml_text.alignment == SGMLINHERIT_ALIGNMENT)
  469.          new->sgml_text.alignment = SGMLALIGNMENT_LEFT;
  470.  
  471.        if (new->sgml_text.sensitive == SGMLINHERIT_SENSITIVITY)
  472.          new->sgml_text.sensitive = FALSE;
  473.  
  474.        if (new->sgml_text.normal_rendition.outline == SGMLINHERIT_OUTLINE)
  475.          new->sgml_text.normal_rendition.outline = FALSE;
  476.  
  477.        if (new->sgml_text.normal_rendition.underline == SGMLINHERIT_UNDERLINE)
  478.          new->sgml_text.normal_rendition.underline = 0;
  479.  
  480.        if (new->sgml_text.normal_rendition.underline_height == SGMLINHERIT_UNDERLINEHEIGHT)
  481.          new->sgml_text.normal_rendition.underline_height = 0;
  482.  
  483.        if (new->sgml_text.normal_rendition.font == SGMLINHERIT_FONT)
  484.          new->sgml_text.normal_rendition.font = XLoadQueryFont(XtDisplayOfObject((Widget) new),"fixed");
  485.  
  486.        if (new->sgml_text.sensitive_rendition.outline == SGMLINHERIT_OUTLINE)
  487.          new->sgml_text.sensitive_rendition.outline = FALSE;
  488.  
  489.        if (new->sgml_text.sensitive_rendition.underline == SGMLINHERIT_UNDERLINE)
  490.          new->sgml_text.sensitive_rendition.underline = 0;
  491.  
  492.        if (new->sgml_text.sensitive_rendition.underline_height == SGMLINHERIT_UNDERLINEHEIGHT)
  493.          new->sgml_text.sensitive_rendition.underline_height = 0;
  494.  
  495.        if (new->sgml_text.sensitive_rendition.font == SGMLINHERIT_FONT)
  496.          new->sgml_text.sensitive_rendition.font = XLoadQueryFont(XtDisplayOfObject((Widget) new),"fixed");
  497.     }
  498.  
  499.   SetFontInfo(new);
  500. }
  501. /*--------------------------------------------------------------*/
  502. /* Call the create Callback:                                    */
  503. /*--------------------------------------------------------------*/
  504.  
  505. static void CallCreateCallback(w,event)
  506. SGMLTextObject w;
  507. XEvent         *event;
  508. {
  509.     SGMLTextCallbackStruct cb;
  510.  
  511.     cb.reason = SGMLTEXT_CREATE;
  512.     cb.event = event;
  513.     cb.text   = w->sgml_text.text;
  514.     cb.length = w->sgml_text.length;
  515.     cb.param  = w->sgml_text.param;
  516.     cb.param_length = w->sgml_text.param_length;
  517.   
  518.     XtCallCallbacks((Widget) w,SGMLNcreateCallback,(XtPointer) &cb);
  519. }
  520. /*--------------------------------------------------------------*/
  521. /* Call the map Callback:                                       */
  522. /*--------------------------------------------------------------*/
  523.  
  524. static void CallMapCallback(w,event)
  525. SGMLTextObject w;
  526. XEvent         *event;
  527. {
  528.     SGMLTextCallbackStruct cb;
  529.  
  530.     cb.reason = SGMLTEXT_MAP;
  531.     cb.event = event;
  532.     cb.text   = w->sgml_text.text;
  533.     cb.length = w->sgml_text.length;
  534.     cb.param  = w->sgml_text.param;
  535.     cb.param_length = w->sgml_text.param_length;
  536.   
  537.     XtCallCallbacks((Widget) w,SGMLNmapCallback,(XtPointer) &cb);
  538. }
  539. /*--------------------------------------------------------------*/
  540. /* Destroy the widget: release all memory alocated              */
  541. /*--------------------------------------------------------------*/
  542.  
  543. static void Destroy (w)
  544. SGMLTextObject w;
  545. {
  546.     FreeFontInfo(w);
  547.  
  548.     XtFree(w->sgml_text.text);
  549.     XtFree(w->sgml_text.param);
  550.     XtRemoveAllCallbacks ((Widget) w,SGMLNactivateCallback);
  551.     XtRemoveAllCallbacks ((Widget) w,SGMLNcreateCallback);
  552. }
  553.  
  554. /*------------------------------------------------------------------*/
  555. /* SetValues : redraw only for font or color changes                */
  556. /*------------------------------------------------------------------*/
  557.  
  558. static Boolean SetValues (current, request, new)
  559. SGMLTextObject current, request, new;
  560. {
  561.     Boolean    redraw = FALSE;
  562.  
  563. #define HAS_CHANGED(a)    (new->sgml_text.a != current->sgml_text.a)
  564.  
  565.     if (HAS_CHANGED(text))
  566.       {
  567.         XtFree(current->sgml_text.text);
  568.         new->sgml_text.text   = new->sgml_text.text?XtNewString(new->sgml_text.text):NULL;
  569.         new->sgml_text.length = new->sgml_text.text?strlen(new->sgml_text.text):0;
  570.       }
  571.  
  572.     if (HAS_CHANGED(param))
  573.       {
  574.         XtFree(current->sgml_text.param);
  575.         new->sgml_text.param  = new->sgml_text.param?XtNewString(new->sgml_text.param):NULL;
  576.         new->sgml_text.length = new->sgml_text.param?strlen(new->sgml_text.param):0;
  577.       }
  578.  
  579.     if (HAS_CHANGED(sensitive))
  580.       {
  581.           FreeFontInfo(new);
  582.           SetFontInfo(new);
  583.           redraw = TRUE;
  584.       } 
  585.     else if (new->sgml_text.sensitive)
  586.       {
  587.         if (HAS_CHANGED(sensitive_rendition.color) || 
  588.             HAS_CHANGED(sensitive_rendition.font)  || 
  589.             HAS_CHANGED(sensitive_rendition.underline_height))
  590.         {
  591.           FreeFontInfo(new);
  592.           SetFontInfo(new);
  593.           redraw = TRUE;
  594.         }
  595.       }  
  596.     else 
  597.       {
  598.         if (HAS_CHANGED(normal_rendition.color) || 
  599.             HAS_CHANGED(normal_rendition.font)  || 
  600.             HAS_CHANGED(normal_rendition.underline_height))
  601.         {
  602.           FreeFontInfo(new);
  603.           SetFontInfo(new);
  604.           redraw = TRUE;
  605.         }
  606.       } 
  607.     return redraw;
  608.  
  609. #undef HAS_CHANGED
  610.  
  611. }
  612.  
  613. /*--------------------------------------------------------------*/
  614. /* Redisplay                                                    */
  615. /*--------------------------------------------------------------*/
  616.  
  617. static void Redisplay(t,event,region)
  618. SGMLTextObject t;
  619. XEvent *event;
  620. Region region;
  621. {
  622. }
  623.  
  624. /*--------------------------------------------------------------*/
  625. /* Compute Size:                                                */
  626. /*--------------------------------------------------------------*/
  627.  
  628. static void ComputeSize(w,geom,Adjust,Closure)
  629. SGMLTextObject w;
  630. SGMLGeometry *geom;
  631. AdjustSizeProc Adjust;
  632. Opaque Closure;
  633. {
  634. }
  635.  
  636. /*--------------------------------------------------------------*/
  637. /* Adjust Size:                                                 */
  638. /*--------------------------------------------------------------*/
  639.  
  640. static Boolean AdjustSize(w,y,ascent,depth)
  641. SGMLTextObject w;
  642. Position y;
  643. Dimension ascent, depth;
  644. {
  645.   return TRUE;
  646. }
  647.  
  648. /*--------------------------------------------------------------*/
  649. /* Adjust Position:                                             */
  650. /*--------------------------------------------------------------*/
  651.  
  652. static void AdjustPosition(w)
  653. SGMLTextObject w;
  654. {
  655. }
  656.  
  657. /*--------------------------------------------------------------*/
  658. /* Hilite:                                                      */
  659. /*--------------------------------------------------------------*/
  660.  
  661. static void Hilite(w,state)
  662. SGMLTextObject w;
  663. Boolean state;
  664. {
  665. }
  666.  
  667. /*--------------------------------------------------------------*/
  668. /* MakeVisible:                                                 */
  669. /*--------------------------------------------------------------*/
  670.  
  671. static void MakeVisible(w)
  672. SGMLTextObject w;
  673. {
  674. }
  675.  
  676. /*--------------------------------------------------------------*/
  677. /* Activate:                                                    */
  678. /*--------------------------------------------------------------*/
  679.  
  680. static void Activate(w,event)
  681. SGMLTextObject w;
  682. XEvent *event;
  683. {
  684.     SGMLTextCallbackStruct cb;
  685.  
  686.     /* Fill callback struct */
  687.  
  688.     cb.text          = w->sgml_text.text;
  689.     cb.length        = w->sgml_text.length;
  690.     cb.param         = w->sgml_text.param;
  691.     cb.param_length  = w->sgml_text.param_length;
  692.     cb.reason        = SGMLTEXT_ACTIVATE;
  693.     cb.event         = event;
  694.  
  695.     XtCallCallbacks ((Widget) w, SGMLNactivateCallback,(XtPointer) &cb);
  696. }
  697.  
  698. /*--------------------------------------------------------------*/
  699. /* Contains:                                                    */
  700. /*--------------------------------------------------------------*/
  701.  
  702. static Widget Contains(w,x,y)
  703. SGMLTextObject w;
  704. Position x,y;
  705. {
  706.   return NULL;
  707. }
  708.  
  709. /*--------------------------------------------------------------*/
  710. /* _SGMLBreak:                                                  */
  711. /*--------------------------------------------------------------*/
  712.  
  713. void _SGMLBreak(geom,space)
  714. SGMLGeometry *geom;
  715. Dimension space; 
  716. {
  717.   if (!geom->broken)
  718.   {
  719.     geom->coord.y += geom->coord.depth;
  720.     geom->coord.y += space;
  721.     geom->space = space;
  722.     geom->broken = TRUE;
  723.   }
  724.   else
  725.   {
  726.     if (space > geom->space) 
  727.     {  
  728.       geom->coord.y += space - geom->space;
  729.       geom->space = space;
  730.     }
  731.   }
  732.   geom->coord.x = 0;
  733.   geom->coord.depth = 0;
  734.   geom->coord.ascent = 0;
  735.   geom->alignment = SGMLALIGNMENT_NONE; 
  736.   geom->leave_space = FALSE; 
  737. }
  738. /*-----------------------------------------------------------------------*/
  739. /* Create a new SGMLTextObject                                           */
  740. /*-----------------------------------------------------------------------*/
  741.  
  742. Widget SGMLCreateText(parent,name,al,ac)
  743. Widget parent;
  744. char   *name;
  745. ArgList al;
  746. int     ac;
  747. {
  748.     return XtCreateWidget(name,sGMLTextObjectClass,parent,al,ac);
  749. }
  750.